<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.view');
class LinkViewLinks extends JViewLegacy{
	function display($tpl = null) {
		
		$items = $this->get('Items');
		$pagination = $this->get('Pagination');
		if (count($errors = $this->get('Errors'))){
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		}
		
		$this->items = $items;
		$this->pagination = $pagination;
		
		$this->state = $this->get('State');
		
		LinkHelper::addSubmenu('links');
		
		$this->addToolBar();
		$this->sidebar = JHtmlSidebar::render();
		parent::display($tpl);
		$this->setDocument();
	}
	
	protected function addToolBar(){
		$canDo = LinkHelper::getActions();
		JToolBarHelper::title(JText::_('Link Manager'), 'Link');
		if ($canDo->get('core.create')) 
		{
			JToolBarHelper::addNew('link.add', 'JTOOLBAR_NEW');
		}
		if ($canDo->get('core.edit')) 
		{
			JToolBarHelper::editList('link.edit', 'JTOOLBAR_EDIT');
		}
		
		
		if ($canDo->get('core.delete')) 
		{
			JToolBarHelper::deleteList('', 'links.delete', 'JTOOLBAR_DELETE');
		}
		if ($canDo->get('core.admin')) 
		{
			JToolBarHelper::divider();
			JToolBarHelper::preferences('com_link');
		}
		
		
	}
	
	protected function setDocument(){
		$document = JFactory::getDocument();
		$document->setTitle(JText::_('Link Manager'));
	}
}
